Lab 01 - Introduction to Linux

Introduction to Linux

IRiM and Fossbot4AI logos

1. Activity Identity

Activity title Introduction to Robotics
Topic Linux / Robotics / IoT
Authors Institute of Robotics and Machine Intelligence
Dominik Belter, Jakub Chudzinski, Marcin Czajka, Kamil MΕ‚odzikowski
Target learners Bachelor (Computer Science / IT, Robotics)
Estimated duration 1.5 hour
Difficulty level Beginner
FOSSBot environment Linux workstation
Licence CC BY 4.0

2. Learning Objectives and Competences

ID Learning outcome Related competences Assessment evidence
LO1 Students will be able to work efficiently in the Linux terminal using autocompletion, history, command chaining and built-in help (--help, man). Linux operating system knowledge; gathering and interpreting information from documentation Screenshot of the IPv4 address from Task 2.1 (Submission item 1)
LO2 Students will be able to manage files and directories from the command line (including wildcards) and edit text files in nano and vim. Linux operating system knowledge; selecting programming tools essential for working with a robot Screenshot of the time vim output from Task 4.2 (Submission item 2)
LO3 Students will be able to connect to another lab workstation over SSH and transfer files with scp and rsync. Linux operating system knowledge; selecting programming tools essential for working with a robot Screenshots of the SSH session and remote ls (Submission items 3 and 4)

3. Prerequisites

4. Required Material and Setup

Category Item Version / Quantity Notes
Hardware Workstation 1 per student Any Linux PC.
Software OpenSSH client, rsync, nano, vim bundled with most Linux distributions Pre-installed on the lab workstations.
Software tree installed during Task 5.1 Installed via sudo apt install tree as part of the lab.

5. Safety, Ethics and Accessibility Notes

The only risks in this lab are operational:

6. Scenario and Problem Statement

During this laboratory you will work with a remote machine - another workstation in the lab. You will reach it from the terminal of your own workstation over the network. The same techniques you learn here will be used in later labs to connect to a FOSSBot (a small mobile robot built around a Raspberry Pi).

7. Lab Workflow

Phase Student action Expected output Time
1. Prepare Log in and open a terminal Working shell 5 min
2. Terminal basics Practice autocompletion, history, help; explore ip via man Familiarity with man, --help, Ctrl-R 15 min
3. Files Copy, move, delete, create files; use wildcards A scratch directory populated and cleaned up 20 min
4. Text editors Edit a file in both nano and vim A modified text file 15 min
5. Packages Install a package with apt Installed package 7 min
6. Remote access SSH, transfer files with scp/rsync, shut down a remote machine Active SSH session, files transferred, shutdown executed 28 min

8. Step-by-Step Instructions

Step 1 - Environment preparation

πŸ’‘ Lab workstation credentials. Every workstation in the lab uses the same local account: username put, password lrm. Use these credentials to log in to your machine, and the same pair to SSH into another machine in the lab in Step 6.

  1. Log in to your lab workstation.

  2. Open a terminal (Ctrl+Alt+T on Ubuntu).

Expected result: A terminal window is open and the prompt looks similar to put@host:~$.

Step 2 - Terminal basics

The three commands you will use most often to find your way around the filesystem:

Try them now:

pwd
ls
cd /tmp
pwd
cd ~

Once you can move around, the shortcuts below make every command faster.

  1. Tab completion. Start typing a command or path and press Tab. If a single completion exists, the shell finishes the word for you. If several completions are possible, press Tab twice to list them. Try:
cd /us<Tab>
  1. History. Use the Up / Down arrow keys to walk through the commands you have already run in this session. For older history, press Ctrl+R and start typing - the shell will incrementally search backwards.

  2. Re-running the previous command. !! expands to the last command you ran. The classic example is forgetting sudo:

apt update           # fails: permission denied
sudo !!              # re-runs as: sudo apt update
  1. Chaining commands. Use && to run a second command only if the first succeeds, and ; to run a second command regardless. For example:
mkdir scratch && cd scratch

vs.

mkdir scratch ; cd scratch
  1. Clearing the screen. clear (or Ctrl+L) wipes the visible terminal.

  2. Built-in help. Almost every command supports --help for a short reference:

ls --help

For a longer manual, use man:

man ls

man opens a pager - a read-only viewer that fills the terminal. While the pager is open, your terminal does not accept normal shell commands; instead it reacts to single-key commands:

πŸ’‘ Tip: Searching inside man is the fastest way to jump straight to a section of interest. For example, /EXAMPLES followed by Enter jumps to the EXAMPLES section of any manual page.

Task 2.1

The ip command prints information about network interfaces (your IP address, MAC address, link state). You will need it whenever you debug a network problem on any machine you SSH into. Open its manual page with man ip and use the EXAMPLES section to find a command that prints only the IPv4 addresses of all interfaces. Run it on your workstation.

Expected result: You can move between commands with the arrow keys, complete paths with Tab, and you have read the ip manual far enough to identify a relevant example.

πŸ“Έ Capture for submission: screenshot the terminal output that shows your IPv4 address. Press Print Screen to take a screenshot; files are saved to ~/Pictures/Screenshots/.

Step 3 - Managing files and directories

The basic file-manipulation commands all share a similar shape: command [flags] source destination.

  1. Clean up state from any previous lab session and create a fresh scratch directory. Remove leftover screenshots and any leftover work, then create a new empty scratch directory:
rm -rf ~/Pictures/Screenshots /tmp/linux-lab && mkdir /tmp/linux-lab

πŸ’‘ Tip: Like most file commands, rm accepts multiple paths in one call - that is why we can clear both directories with a single rm. The && then only runs mkdir if rm succeeded - which is the safety chain you read about in Step 2.

All lab work happens in /tmp/linux-lab rather than in your home directory. /tmp is the conventional location for scratch work and is wiped on every reboot, so the workstation stays clean for the next user.

  1. Enter the scratch directory and verify with pwd:
cd /tmp/linux-lab
pwd

The expected output of pwd is /tmp/linux-lab.

  1. Create empty files with touch:
touch note.txt report.txt data.csv
  1. Copy a file to a new name:
cp note.txt note-backup.txt

For entire directory trees, add -r (recursive):

cp -r /tmp/linux-lab /tmp/linux-lab-copy
  1. Move or rename a file with mv:
mv note-backup.txt archived-note.txt

If the second argument is an existing directory, mv moves the file into it instead of renaming.

  1. Delete files with rm. Use -r for directories. Be careful - this operation is irreversible (files are not moved to a recycle bin).
rm archived-note.txt
rm -r /tmp/linux-lab-copy
  1. Wildcards (globs) let you act on many files at once:

Examples:

cp *.txt /tmp/                  # copy every .txt file from the current dir to /tmp
rm /tmp/linux-lab/[0-9]*        # delete files in the scratch dir whose name starts with a digit

πŸ’‘ Tip: Before running a destructive command with a glob, replace rm with ls first. If ls *.txt lists what you expected, then rm *.txt will delete exactly those files.

Task 3.1

Inside /tmp/linux-lab, create the files log1.txt, log2.txt, log3.txt, data.csv and image.png. Using a single rm command with a glob, delete only the .txt files.

Expected result: After Task 3.1, ls /tmp/linux-lab shows only data.csv and image.png.

Step 4 - Text editors in the terminal

Whenever you SSH into a remote machine, you have no GUI and must edit files from the terminal. Two editors are universally available: nano (simple, menu-driven) and vim (powerful, modal).

Nano

nano is the right choice for the occasional edit. Open or create a file with:

nano note.txt

The most important shortcuts are listed at the bottom of the screen. The essentials:

Vim

vim is faster once you know it, but it is modal - there is a separate mode for moving the cursor and a separate mode for typing text. Open a file with:

vim note.txt

Modes:

Commands (typed in Normal mode, confirmed with Enter):

πŸ’‘ Tip: If you find yourself stuck in vim, press Esc a few times and then type :q! followed by Enter. That always gets you out without saving.

Task 4.1

Use vim to add a single line of text to /tmp/linux-lab/note.txt, save and quit.

Task 4.2

Re-open the same file with time to measure how long the whole editing session takes:

time vim /tmp/linux-lab/note.txt

Add another line, save and quit. The time output reports real, user and sys durations.

Expected result: note.txt contains the lines you typed, and the time command printed a real duration of a few seconds.

πŸ“Έ Capture for submission: screenshot the terminal output showing the time line with real/user/sys durations.

Step 5 - Installing packages with apt

On Ubuntu, software is installed from central repositories with apt. Avoid installing software by downloading .run files from random websites - apt keeps everything tracked and updatable.

The most common operations:

sudo apt update                    # refresh the list of available packages
apt search <keyword>               # find a package by name or description
sudo apt install <package-name>    # install a package
sudo apt remove <package-name>     # uninstall a package

Task 5.1

Read the output of apt --help. Then search for the package tree, remove any version left over from a previous session and install it:

apt search tree
sudo apt remove -y tree   # cleanup from a previous session (harmless if tree is not installed)
sudo apt install tree

πŸ’‘ Tip: If tree was not installed yet, the remove step will print Package 'tree' is not installed, so not removed and exit cleanly. The operation is idempotent - it leaves the system in the same state regardless of whether the package was there.

Confirm the install by running tree on the scratch directory you created in Step 3:

tree /tmp/linux-lab

Expected result: tree prints a small directory tree similar to:

/tmp/linux-lab
β”œβ”€β”€ data.csv
β”œβ”€β”€ image.png
└── note.txt

1 directory, 3 files

Step 6 - Remote access to another machine

In this step you will connect from your own terminal to another workstation in the lab and run commands on it as if you were sitting at it.

Connecting with ssh

The ssh command opens an interactive shell on a remote machine:

ssh <user>@<remote-ip>

Throughout this lab, replace <remote-ip> with the IPv4 address of another lab workstation - you will obtain it in Task 6.1. Every lab workstation has the same local put account (with the password from Step 1), so put is the username you authenticate as on the remote machine.

So to log in as user put on a remote machine:

ssh put@<remote-ip>

If the remote username is the same as your local username, you may omit it:

ssh <remote-ip>

πŸ’‘ Tip: The first time you connect to a new host, SSH asks you to verify the host’s fingerprint. Type yes to continue. This protects you from connecting to an imposter on subsequent sessions.

Task 6.1

Get the IPv4 address of another workstation in the lab (ask whoever is using it). Connect to it with SSH (account: put, password: lrm). Once connected, run whoami and hostname to confirm you are on the remote machine. Then end the session with exit.

πŸ“Έ Capture for submission: while you are connected, take a screenshot of the terminal - the prompt should show the remote hostname, not your own.

Transferring files with scp

scp (secure copy) has the same shape as cp, but the source or destination can be on a remote machine. The remote path uses the syntax <user>@<address>:<path>:

πŸ’‘ Tip: scp opens its own SSH connection to the remote machine to do the transfer. Run it from your local terminal, exactly as you run any local command - do not ssh to the remote first. The connection lives only for the duration of the copy and closes automatically when the transfer finishes.

# upload a single file
scp local-file.txt put@<remote-ip>:~/

# upload a whole directory
scp -r local-directory put@<remote-ip>:~/

# download a single file
scp put@<remote-ip>:~/remote-file.txt ./

# download a whole directory
scp -r put@<remote-ip>:~/remote-directory ./

Task 6.2

Download any file from the remote machine into /tmp/linux-lab/ using scp. Edit it locally (with nano or vim) and upload it back to the remote machine under a new name. Verify the new file is there by SSH-ing in and running ls.

πŸ“Έ Capture for submission: screenshot the ls output on the remote machine showing the file you uploaded back.

Transferring files with rsync

rsync is incremental - it only sends the parts of files that have changed, and it can resume interrupted transfers. This makes it the right tool for moving large directories (such as datasets or log files) to and from a remote machine. A reasonable default invocation:

rsync -PHAXphax <local_directory> <user>@<address>:<target_directory>
rsync -PHAXphax <user>@<address>:<remote_file> <local_directory>

Task 6.3

Look up what each flag in -PHAXphax does (start with man rsync and search for each letter). Then use rsync to copy a directory to the remote machine.

Power management with systemctl

Most modern Linux distributions use the systemd init system. The same systemctl command shuts down, reboots and suspends the machine:

The first two also have short aliases: poweroff and reboot.

Task 6.4

Ask a classmate at the neighboring station for their IPv4 address. SSH into their computer and shut it down:

sudo systemctl poweroff

You will need to type the put password again because of sudo. The remote machine shuts down within a few seconds and your SSH session drops - that is the expected outcome.

Expected result: You have opened at least one SSH session to a remote machine, successfully transferred a file in both directions using scp and a directory using rsync, and finally shut down the remote workstation with sudo systemctl poweroff.

9. Analysis Questions

  1. Which of the techniques from Step 2 (Tab, Ctrl+R, !!, command chaining) saved you the most keystrokes during this lab? Give a concrete example.

  2. What is the practical difference between scp -r foo bar and rsync -PHAXphax foo bar when you copy a 500 MB directory and the network drops halfway through?

  3. You want to copy /tmp/linux-lab/note.txt from your local workstation to ~/ on a remote machine. From which terminal do you run scp - your own local terminal, or one that is already SSH-ed into the remote? Justify briefly.

  4. List two commands from this lab that needed sudo. In each case, what would the system do if you ran the command without sudo?

10. Submission Requirements

11. References and Open Licence

The Creative Commons Attribution 4.0 International (CC BY 4.0) license allows users to share, copy, distribute, and adapt the work, even for commercial purposes, as long as proper credit is given to the original creator.

EU funding disclaimer

Funded by the European Union. Views and opinions expressed are however those of the author(s) only and do not necessarily reflect those of the European Union or the European Education and Culture Executive Agency (EACEA). Neither the European Union nor EACEA can be held responsible for them.